'use strict'
const sessionMgr = require('./sessionMgr')
const route = require('../module/route')
const nodeMgr = require('./nodeMgr')
const sceneMgr = require('./sceneMgr')
const nodeCall = require('../module/nodeCall')


//子节点注册
nodeCall.setCall('bindNodeName', function(session, msg) {
    let nodeName = msg.nodeName
    let nodeType = msg.nodeType
    nodeMgr.bind(session.id, nodeName, nodeType)
})

//获取子节点的请求方法
nodeCall.setCall('getRequestRoute', function(nodeSession, msg) {
    let nodeType = msg.nodeType
    let routeName = msg.routeName
    let errMap = msg.errMap
    for (let name of routeName) {
        route.setNode(name, nodeType)
    }

    for (let i in errMap) {
        route.errMap[i] = errMap[i]
    }
})

//获取子节点的所有场景
nodeCall.setCall('getAllScene', function(nodeSession, msg) {
        let nodeName = msg.nodeName
        let sceneArray = msg.sceneArray
        for (let sceneId of sceneArray) {
            route.setNode(sceneId, nodeName)
        }
    })
    //进入公共场景
nodeCall.setCall('enterScene', function(nodeSession, msg) {
        let playerSession = sessionMgr.getByPid(msg.pId)
        sceneMgr.getSceneSerById(msg.sceneId).addClient(playerSession)
    })
    //推送消息到该玩家
nodeCall.setCall('pushMsgToPlayer', function(nodeSession, msg) {
        sessionMgr.pushMsgToPlayer(msg.pId, msg.data, msg.route)
    })
    //推送消息到当前场景
nodeCall.setCall('pushMsgsToScene', function(nodeSession, msg) {
    sessionMgr.pushMsgsToScene(msg.sceneId, msg.data, msg.route)
})
